/// a lot of forward ideas snuck in here for now just calculates the collision state of two objects
/// can be used to link two objects or reused to test multiple different objects

/// if not used right will throw out all sorts of evil pointer errors 

class collision_detector {

  boolean collision;

  particle one;
  particle two;

  float distance= -1;
  
  float[] location = new float[2];

  collision_detector() {
  } 

  void set_particle_one(particle one) {
    this.one = one;
  }

  /*
  void set_particle_two(particle two ) {
   this.two = two;
   }
   */

  boolean is_collision(particle two) {
    this.two = two; 
    return is_collision();
  }

  boolean is_collision(particle one, particle two) {
    this.one = one;
    this.two = two;
    return is_collision();
  }

  boolean is_collision() {
    distance = collision_distance();
    collision = (distance < one.radius+two.radius)?true:false;
    return collision;
  }

/// dump all saved data
  void reset() {
    one = null;
    two  = null;
    distance  = -1;
    collision  = false;
    location[0]  = -1;
    location[1]  = -1;
  }

  float[] get_location() {
    ////// calculate the point of impact of the last collision
    return location;
  }

  float collision_distance() {
    return distance(one.x_loc,one.y_loc,two.x_loc,two.y_loc);
  }
}

